home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / echsys10.zip / ENVSET.ASM < prev    next >
Assembly Source File  |  1989-09-25  |  28KB  |  727 lines

  1.                  PAGE   60,132
  2.  
  3.                  ;Usage is: call env_set  ds:si -> length,string
  4.  
  5.                  ;      length is 1 byte long, <128
  6.                  ;         if high bit on, primary environment is set.
  7.                  ;      string is of form: name=value
  8.  
  9.                  ;   Copyright 1987, A. B. Krueger GPW MI 48236
  10.                  ;   All rights reserved. Contact "ARNY KRUEGER"
  11.                  ;   at the EXEC-PC BBS (414-964-5160) for permission
  12.                  ;   to use commercially.
  13.                  ;
  14.                  ;   Stripped version by TapirSoft Gisbert W.Selke:
  15.                  ;   Commented out parts with ';;' at start of line.
  16.                  ;   See ENV_SET.ASM for Arny's full source.
  17.                  ;   Also, fixed a minor bug when trying to delete
  18.                  ;   an inexistent variable.
  19.                  ;
  20.  
  21.                  ;Clone of SET command that demonstrates updating
  22.                  ;      the environment string.
  23.                  ;If there is no secondary command processor, the
  24.                  ;      global environment is updated
  25.                  ;If there is a secondary command processor, then
  26.                  ;      its environment is updated
  27.  
  28. sb               segment at 0      ;equates storage blocks and psp's
  29.  
  30. sb_kind          db     ' '        ;type of storage block: 'M' or 'Z'
  31. sb_psp           dw     ?          ;psp segment address
  32. sb_length        dw     ?          ;sb length in paragraphs
  33. sb_head_length   equ    10h        ;length of sb header
  34.                  org    sb_head_length
  35. sb_data          db     ?          ;data in block
  36.  
  37.                  org    0h         ;program segement prefix equates
  38. psp_ret_int      dw     ?          ;int 20h
  39.                  org    2Ch
  40. psp_env          dw     ?          ;segment address of environment
  41.                  org    50h
  42. psp_dos_function dw     ?          ;address of function dispatcher
  43.                  org    80h
  44. psp_parm_string  db     ?          ;1 byte length plus parm string
  45.  
  46. psp_length       equ    100h
  47.  
  48. sb               ends
  49.  
  50. cseg             segment para public
  51.                  assume cs:cseg,ds:cseg,es:sb
  52.                  public env_set
  53.  
  54.                  ;local  data
  55.  
  56. cr               equ    13
  57. lf               equ    10
  58.  
  59. sb_count         dw    0            ;count of sb's encountered
  60. sb_shell         dw    0            ;segment address of shell  sb
  61. sb_shell_env     dw    0            ;segment address of global env sb
  62. sb_secondary     dw    0            ;segment address of secondary command.com
  63. sb_secondary_env dw    0            ;segment address of secondary command env
  64.  
  65. ;;fatal_msg       equ    80h
  66. ;;error_msg       equ    40h
  67. ;;info_msg        equ    20h
  68. ;;msg_flag        db     fatal_msg+error_msg ;+info_msg   ;set flags
  69. ;;                db     'Copyright 1987, A. B. Krueger GPW MI 48236'
  70. ;;secondary_msg   db     info_msg,'Secondary '
  71. ;;command_found   db     info_msg,'COMMAND.COM found',cr,lf,'$'
  72. ;;bad_dos_msg     db     fatal_msg,'Must be running under DOS 2.0 or above',cr,lf,'$'
  73. ;;bad_sb_msg      db     fatal_msg,'Bad storage block',cr,lf,'$'
  74. ;;bad_env_msg     db     error_msg,'Bad environment block',cr,lf,'$'
  75. ;;command_lost    db     error_msg,'Shell never found',cr,lf,'$'
  76. ;;addbadmsg       db     error_msg,'Environment corrupt',cr,lf,'$'
  77. ;;addmsg          db     info_msg,'Addition requested',cr,lf,'$'
  78. ;;removemsg       db     info_msg,'Removal requested',cr,lf,'$'
  79. ;;env_set_nospace db     error_msg,'No space in environment string',cr,lf,'$'
  80. ;;env_set_syntax  db     error_msg,'Set string syntax error',cr,lf,'$'
  81.  
  82. ;;type_string     proc   near          ;type message at offset in dx
  83. ;;                push   ax            ;save registers
  84. ;;                push   cx
  85. ;;                push   dx
  86. ;;                push   si
  87. ;;
  88. ;;                mov    si,dx         ;get message level
  89. ;;                lodsb
  90. ;;                and    al,msg_flag   ;compare to what sells
  91. ;;                jz     type_ret      ;if not on list, send to bit bucket
  92. ;;
  93. ;;                mov    dx,si
  94. ;;                mov    ax,0900h
  95. ;;                int    21h
  96. ;;type_ret:
  97. ;;                pop    si
  98. ;;                pop    dx
  99. ;;                pop    cx
  100. ;;                pop    ax
  101. ;;                ret
  102. ;;type_string     endp
  103.  
  104. get_first_sb    proc   near       ;get first storage block, point es at it
  105.                 push   ax
  106.                 push   bx
  107.                 mov    ax,5200h
  108.                 int    21h        ;es:bx points to memory block anchor+2
  109.                 dec    bx
  110.                 dec    bx
  111.                 mov    es,es:[bx] ;get first memory block address into es
  112.                 pop    bx
  113.                 pop    ax
  114.                 ret
  115. get_first_sb    endp
  116.  
  117. get_next_sb     proc   near
  118.                 push   ax
  119.                 mov    ax,es             ;get current paragraph
  120.                 add    ax,sb_length      ;add in number of paragraphs
  121.                 inc    ax                ;add 1 for header
  122.                 mov    es,ax             ;set new extra segment address
  123.                 pop    ax
  124.                 ret
  125. get_next_sb     endp
  126.  
  127.  
  128. find_secondary_env proc  near       ;find env sb's for current program sb
  129.                 push   ax           ;pointed to by es
  130.                 push   es
  131.                 mov    ax,es        ;get address of secondary cp's sb
  132.                 inc    ax           ;get its psp address
  133. find_secondary_env_loop:
  134.                 call   get_next_sb  ;get next sb
  135.                 cmp    ax,sb_psp    ;match secondary's psp?
  136.                 jne    find_secondary_env_next    ;if not, skip
  137.  
  138.                 mov    sb_secondary_env,es        ;otherwise, save
  139.                 jmp    find_secondary_env_exit    ;and check no further
  140.                                                   ;lest we trash a .BAT block
  141. find_secondary_env_next:
  142.                 cmp    sb_kind,'Z'                ;last block?
  143.                 jne    find_secondary_env_loop
  144.  
  145. find_secondary_env_exit:
  146.                 pop    es
  147.                 pop    ax
  148.                 ret
  149. find_secondary_env endp
  150.  
  151. command_test    proc   near         ;test program storage block at es:0
  152.                 push   ax
  153.                 push   bx
  154.                 push   cx
  155.                 push   dx
  156.                 push   ds
  157.                 push   es
  158.                 push   si
  159.  
  160.                 cmp    sb_count,2
  161.                 ja     command_second
  162.  
  163. ;;              mov    dx,offset command_found
  164. ;;              call   type_string
  165.                 mov    sb_shell,es
  166.                 jmp    command_test_good
  167.  
  168. command_second:
  169.                 cmp    sb_shell,0                       ;did we find shell?
  170.                 je     command_first_bad                ;if not, error
  171.  
  172.                 cmp    word ptr es:psp_env+sb_head_length,0  ;check environment of program
  173.                 je     command_test_good                 ;if no environment, quit
  174.  
  175.                 push   sb_shell
  176.                 pop    ds                               ;ds points to shell
  177.                 mov    al,byte ptr es:sb_head_length+psp_length
  178.                 cmp    al,0E9h                          ;a JMP?
  179.                 jne    command_test_good                ;if not, no harm done
  180.  
  181.                 cmp    al,byte ptr ds:sb_head_length+psp_length   ;check 1st instruction
  182.                 jne    command_first_bad
  183.  
  184.                 mov    si,sb_head_length+psp_length
  185.                 mov    di,sb_head_length+psp_length
  186.                 mov    cx,10      ;look at 10 words of code
  187.                 repz   cmpsw
  188.                 clc
  189.                 jcxz   command_test_found   ;if they all match, fine
  190.  
  191.                 jmp    command_test_good    ;if not, no harm done
  192.  
  193. command_test_found:
  194.                 push   cs
  195.                 pop    ds
  196.                 mov    sb_secondary,es
  197.  
  198.                 mov    ax,es:psp_env+sb_head_length     ;get env address
  199.                 dec    ax                               ;back up over sb header
  200.                 mo